﻿using System;
using System.Collections.Generic;
using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using Pay.TO;

namespace Pay.Service.AutoMapper {

	public class TopicMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public TopicMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {

			_cfg.CreateMap<Topic, topic_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
				.ForMember(dest => dest.title, src => src.MapFrom(c => c.Title))
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
				.ForMember(dest => dest.show_images, src => src.MapFrom(c => c.ShowImages))
				.ForMember(dest => dest.show_type, src => src.MapFrom(c => c.ShowType))
			   	.ForMember(dest => dest.page_type, src => src.MapFrom(c => c.PageType))
				.ForMember(dest => dest.banner, src => src.MapFrom(c => c.Banner))
				.ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
				.ForMember(dest => dest.remark, src => src.MapFrom(c => c.Remark))
				.ForMember(dest => dest.merchant, src => src.MapFrom(c => c.Merchant))
				.ForMember(dest => dest.topic_groups, src => src.MapFrom(c => c.TopicGroups));

			_cfg.CreateMap<topic_dto, Topic>()
				.ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.Title, src => src.MapFrom(c => c.title))
				.ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
				.ForMember(dest => dest.ShowImages, src => src.MapFrom(c => c.show_images))
				.ForMember(dest => dest.ShowType, src => src.MapFrom(c => c.show_type))
				.ForMember(dest => dest.PageType, src => src.MapFrom(c => c.page_type))
				.ForMember(dest => dest.Banner, src => src.MapFrom(c => c.banner))
				.ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
				.ForMember(dest => dest.Remark, src => src.MapFrom(c => c.remark))
				.ForMember(dest => dest.Merchant, src => src.MapFrom(c => c.merchant))
                .ForMember(dest => dest.TopicGroups, src => src.MapFrom(c => c.topic_groups));

			_cfg.CreateMap<topic_query, TopicQuery>();
			_cfg.CreateMap<topic_model, topic_dto>();
		}
	}
}
